package com.zifeng.feign.fallback;

import com.zifeng.common.R;
import com.zifeng.exception.BizException;
import com.zifeng.exception.ErrorEnum;
import com.zifeng.feign.AssignmentFeignClient;
import com.zifeng.feign.OrderFeignClient;
import com.zifeng.pojo.Assignment;
import com.zifeng.pojo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collections;

import static com.zifeng.exception.ErrorCodeAndMsg.*;

@Slf4j
@Component
public class AssignmentFeignClientFallback implements AssignmentFeignClient {

    @Override
    public R getFinishedAssignments() {
        log.error("获取已完成的任务列表失败");
        return R.error(ASSIGNMENT_FEIGN_GET_FINISHED_LIST_FAIL_CODE, ASSIGNMENT_FEIGN_GET_FINISHED_LIST_FAIL_MSG)
                .put("finishedList", Collections.emptyList());
    }

    @Override
    public R update(Assignment assignment) {
        log.error("更新任务失败，任务为：{}", assignment);
        return R.error(ASSIGNMENT_FEIGN_UPDATE_FAIL_CODE, ASSIGNMENT_FEIGN_UPDATE_FAIL_MSG).put("error", new BizException(ErrorEnum.ASSIGNMENT_FEIGN_UPDATE_FAIL));
    }
}
